package api

import (
	"fiberdemo/app/model"
	"fiberdemo/app/service"
	"fmt"
	"github.com/gofiber/fiber/v2"
)

var Nlp = newNlpApi()

type nlpApi struct {
}


func newNlpApi() *nlpApi {
	return &nlpApi{}
}

func (a *nlpApi) Creatdb(c *fiber.Ctx) error {
	p := new(model.Nlps)
	if err := c.BodyParser(p); err != nil {
		fmt.Println(err)
		return err
	}
	x:= service.CreateCollection(p.Db)

	return c.SendString(x)
}
func (a *nlpApi) Getnlp(c *fiber.Ctx) error {
	p := new(model.Nlps)
	if err := c.BodyParser(p); err != nil {
		fmt.Println(err)
		return err
	}
	x:= service.Geturlval(p.Name)
	return c.JSON(fiber.Map{
		"cab": x,
	})
}
func (a *nlpApi) Insert(c *fiber.Ctx) error {
	p := new(model.Nlps)
	if err := c.BodyParser(p); err != nil {
		fmt.Println(err)
		return err
	}
	x:= service.Insert(p.Name,p.Tab)
	return c.JSON(fiber.Map{
		"cab": x,
	})
}
func (a *nlpApi) Search(c *fiber.Ctx) error {
	p := new(model.Nlps)
	if err := c.BodyParser(p); err != nil {
		return err
	}
	x:= service.SearchNlp(p.Name,p.Top,p.Tab)
	return c.JSON(x)
}
func (a *nlpApi) Delete(c *fiber.Ctx) error {
	p := new(model.Nlps)
	if err := c.BodyParser(p); err != nil {
		fmt.Println(err)
		return err
	}
	x:= service.Nlpdelete(p.Id)
	return c.JSON(fiber.Map{
		"cab": x,
	})
}
